#!/usr/bin/env python
# coding=utf-8
# @FileName  :futures.py
# @Time      :2024/7/8 9:52
# @Author    :jdz
# @description :
import asyncio


def function_that_returns_a_future_object():
    future = asyncio.Future()
    asyncio.get_event_loop().call_later(1, future.set_result, "Future result")
    return future


async def some_python_coroutine():
    await asyncio.sleep(1)
    return "Another coroutine result"


async def main():
    result = await function_that_returns_a_future_object()
    print(result)

    # 使用 asyncio.gather 等待多个任务，结果按照传入的顺序返回
    results = await asyncio.gather(
        function_that_returns_a_future_object(),
        some_python_coroutine()
    )
    print(results)


asyncio.run(main())
